﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Portal.Core;
using Portal.Systems.Model;
using Portal.Web.Utility;
using Portal.Web.Model;
using Portal.Utility;

namespace Portal.Systems.Render
{
    public class PageRenderBll : WebPartTemplate
    {
        public override string Id
        {
            get
            {
                return "PageRenderBll";
            }
        }

        public override string Title
        {
            get
            {
                return "Quản lý trang trên cổng";
            }
        }



        static void CheckPermission(string SiteId)
        {
            try
            {
                string UserId = WebSessionUtility.GetCurrentLoginUser().UserId;
                SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, SystemPermission.StaticId, SystemPermission.funcManage, SystemPermission.funcManage, UserId, true);
            }
            catch (Exception ex)
            {
                string ReturnData = "<div class=CssAccessDenied>" + ex.Message.ToString() + " <span class=CssBack><a href=\"javascript:history.back(-1);\">Quay lại</a></span></div>\r\n";
                throw new Exception(ReturnData);
            }
        }
        public static AjaxOut Draw(string SiteId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                WebSessionUtility.CheckSessionTimeOut();
                CheckPermission(SiteId);
                string UserType = (string)WebEnvironments.Request(SiteId, "type");
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                if (string.IsNullOrEmpty(UserType)) UserType = "";
                string ButtonIconRoot = WebConfig.GetButtonIconRoot(OSiteParam);
                string Html =
                   "<script language=javascript>\r\n" +
                   "    function ClientReading()\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        AjaxOut = Portal.Systems.Render.PageRenderBll.ServerSideReading(SiteId).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +
                   "        document.getElementById('divListPage').innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "    }\r\n" +


                   "    function ClientAdd()\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        document.getElementById('divActionForm').style.display='block';\r\n" +
                   "        document.getElementById('divListForm').style.display='none';\r\n" +
                   "        AjaxOut = Portal.Systems.Render.PageRenderBll.DrawAddForm(SiteId).value;\r\n" +
                   "        document.getElementById('divActionForm').innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "        document.getElementById('txtPage').focus();\r\n" +
                   "    }\r\n" +

                   "    function ClientUpdate(PageId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        document.getElementById('divActionForm').style.display='block';\r\n" +
                   "        document.getElementById('divListForm').style.display='none';\r\n" +
                   "        AjaxOut = Portal.Systems.Render.PageRenderBll.DrawUpdateForm(SiteId, PageId).value;\r\n" +
                   "        document.getElementById('divActionForm').innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "        document.getElementById('txtPage').focus();\r\n" +
                   "    }\r\n" +


                   "    function ClientBack()\r\n" +
                   "    {\r\n" +
                   "        document.getElementById('divActionForm').style.display='none';\r\n" +
                   "        document.getElementById('divListForm').style.display='block';\r\n" +
                   "    }\r\n" +

                   "    function ClientAddPage()\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        PageAlias = document.getElementById('txtPageAlias').value;\r\n" +
                   "        PageTitle = document.getElementById('txtPageTitle').value;\r\n" +
                   "        PageKeyword = document.getElementById('txtPageKeyword').value;\r\n" +
                   "        Active= document.getElementById('drpSelectStatus').value;\r\n" +
                   "        SortIndex= document.getElementById('txtSortIndex').value;\r\n" +
                   "        AjaxOut = Portal.Systems.Render.PageRenderBll.ServerSideAdd(SiteId, PageAlias, PageTitle, PageKeyword, Active, SortIndex).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +
                   "        document.getElementById('divActionForm').innerHTML = '';\r\n" +
                   "        document.getElementById('divActionForm').style.display = 'none';\r\n" +
                   "        document.getElementById('divListPage').innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "        ClientBack();\r\n" +
                   "    }\r\n" +

                   "    function ClientZone(PageId)\r\n"+
                   "    {\r\n"+
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        AjaxOut = Portal.Systems.Render.PageRenderBll.ServerSideGetZoneUrl(SiteId, PageId).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +
                   "        window.open(AjaxOut.RetUrl,'_self');\r\n" +
                   "    }\r\n"+

                   "    function ClientPageConfig(PageId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        AjaxOut = Portal.Systems.Render.PageRenderBll.ServerSideGetPageConfigUrl(SiteId, PageId).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +
                   "        window.open(AjaxOut.RetUrl,'_self');\r\n" +
                   "    }\r\n" +

                   "    function ClientDuplicate(PageId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        AjaxOut = Portal.Systems.Render.PageRenderBll.ServerSideDuplicate(SiteId, PageId).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +
                   "        document.getElementById('divListPage').innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "    }\r\n" +

                   "    function ClientDelete(PageId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        if(confirm('Bạn đã chắc chắn xóa chưa?')==false)return;\r\n" +
                   "        AjaxOut = Portal.Systems.Render.PageRenderBll.ServerSideDelete(SiteId, PageId).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +
                   "        document.getElementById('divListPage').innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "    }\r\n" +

                   "    function ClientSavePage(PageId)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        PageAlias = document.getElementById('txtPageAlias').value;\r\n" +
                   "        PageTitle = document.getElementById('txtPageTitle').value;\r\n" +
                   "        PageKeyword = document.getElementById('txtPageKeyword').value;\r\n" +
                   "        Active = document.getElementById('drpSelectStatus').value;\r\n" +
                   "        SortIndex = document.getElementById('txtSortIndex').value;\r\n" +

                   "        AjaxOut = Portal.Systems.Render.PageRenderBll.ServerSideSave(SiteId, PageId, PageAlias, PageTitle, PageKeyword, Active, SortIndex).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +
                   "        document.getElementById('divActionForm').innerHTML = '';\r\n" +
                   "        document.getElementById('divActionForm').style.display = 'none';\r\n" +
                   "        document.getElementById('divListPage').innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "        ClientBack();\r\n" +
                   "    }\r\n" +
                   "</script>\r\n" +
                   "<div id=divActionForm style=\"display:none;\"></div>\r\n" +
                   "<input type=hidden id=txtUserType value=\"" + UserType + "\">\r\n" +
                   "<div class=FormFunction id=divListForm>\r\n" +
                   " <div class=DatabaseFunction>\r\n" +
                   "        <ul>\r\n" +
                   "            <li onclick=\"javascript:ClientAdd();\"><img class=image src=\"" + ButtonIconRoot + "/Add.png\"><div>Tạo mới</div></li>\r\n" +
                   "            <li onclick=\"javascript:window.open('../../folder.aspx?folder=admin','_self');\"><img class=image src=\"" + ButtonIconRoot + "/back.png\"><div>Quay lại</div></li>\r\n" +
                   "        </ul>\r\n" +
                   "  </div>\r\n" +
                   "  <div id=\"divListPage\" class=tabcontent>\r\n" +
                         ServerSideReading(SiteId).HtmlContent +
                   "  </div>\r\n" +
                   "</div>\r\n";

                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = "<div class=CssAccessDenied>" + ex.Message.ToString() + "</div>\r\n";
            }

            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideReading(string SiteId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {

                PageCls[] Pages = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).ReadingPage(SiteId,null);
                string Subject = "Danh sách trang web trên cổng";
                string Html =
                   "        <h3>" + Subject + "</h3>\r\n" +
                   "            <table>\r\n" +
                   "                <tr>\r\n" +
                   "                    <th class=thIndex>#</th>\r\n" +
                   "                    <th class=thCode>Mã</th>\r\n" +
                   "                    <th>Tiêu đề trang</th>\r\n" +
                   "                    <th>Từ khóa</th>\r\n" +
                   "                    <th></th>\r\n" +
                   "                    <th></th>\r\n" +
                   "                    <th></th>\r\n" +
                   "                    <th></th>\r\n" +
                   "                    <th></th>\r\n" +
                   "                </tr>\r\n";
                for (int iIndex = 0; iIndex < Pages.Length; iIndex++)
                {
                    string UpdateButton = "<input type=button class=button value=\"Sửa\" onclick=\"javascript:ClientUpdate('" + Pages[iIndex].PageId + "');\">";
                    string DeleteButton = "<input type=button class=button value=\"Xóa\" onclick=\"javascript:ClientDelete('" + Pages[iIndex].PageId + "');\">";
                    string ZoneButton = "<input type=button class=button value=\"Vùng\" onclick=\"javascript:ClientZone('" + Pages[iIndex].PageId + "');\">";
                    string ConfigButton = "<input type=button class=button value=\"Thiết lập\" onclick=\"javascript:ClientPageConfig('" + Pages[iIndex].PageId + "');\">";
                    string DuplicateButton = "<input type=button class=button value=\"Sao chép\" onclick=\"javascript:ClientDuplicate('" + Pages[iIndex].PageId + "');\">";
                    Html +=
                       "    <tr>\r\n" +
                       "        <td class=tdIndex>" + (iIndex + 1) + "</td>\r\n" +
                       "        <td class=tdCode>" + Pages[iIndex].PageAlias + "</td>\r\n" +
                       "        <td>" + Pages[iIndex].PageTitle + "</td>\r\n" +
                       "        <td>" + Pages[iIndex].PageKeyword + "</td>\r\n" +
                       "        <td style=\"width:10px;\">" + UpdateButton + "</td>\r\n" +
                       "        <td style=\"width:10px;\">" + DeleteButton + "</td>\r\n" +
                       "        <td style=\"width:10px;\">" + ZoneButton + "</td>\r\n" +
                       "        <td style=\"width:10px;\">" + ConfigButton + "</td>\r\n" +
                       "        <td style=\"width:10px;\">" + DuplicateButton + "</td>\r\n" +
                       "   </tr>\r\n";
                }
                Html +=
                   "    </table>\r\n";

                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }

            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut DrawAddForm(string SiteId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string ButtonIconRoot = WebConfig.GetButtonIconRoot(OSiteParam);
                string SelectStatus = "<select id=drpSelectStatus>\r\n" +
                                      "     <option value=\"0\">Chưa sử dụng</option>\r\n" +
                                      "     <option value=\"1\">Sử dụng</option>\r\n" +
                                      "</select>\r\n";
                string Html =
                   " <div class=DatabaseFunction>\r\n" +
                   "        <ul>\r\n" +
                   "            <li onclick=\"javascript:ClientAddPage();\"><img class=image src=\"" + ButtonIconRoot + "/Save.png\"><div>Ghi lại</div></li>\r\n" +
                   "            <li onclick=\"javascript:ClientBack();\"><img class=image src=\"" + ButtonIconRoot + "/back.png\"><div>Quay lại</div></li>\r\n" +
                   "        </ul>\r\n" +
                   "  </div>\r\n" +
                   "  <div class=CssFormSaveUpdate>\r\n" +
                   "  <h3>Thêm mới trang web</h3>\r\n" +
                   "  <table>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=Col1>Mã trang:</td>\r\n" +
                   "        <td class=Col2><input id=txtPageAlias value=\"\" class=textbox type=textbox></td>\r\n" +
                   "    </tr>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=Col1>Tiêu đề trang:</td>\r\n" +
                   "        <td class=Col2><input id=txtPageTitle class=textbox type=textbox></td>\r\n" +
                   "    </tr>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=Col1>Từ khóa:</td>\r\n" +
                   "        <td class=Col2><input id=txtPageKeyword class=textbox type=textbox></td>\r\n" +
                   "    </tr>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=Col1>Trạng thái:</td>\r\n" +
                   "        <td class=Col2>"+SelectStatus+"</td>\r\n" +
                   "    </tr>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=Col1>Thứ tự:</td>\r\n" +
                   "        <td class=Col2><input id=txtSortIndex class=textbox type=textbox></td>\r\n" +
                   "    </tr>\r\n" +
                   "  </table>\r\n" +
                   "</div>\r\n";

                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }

            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut DrawUpdateForm(string SiteId, string PageId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string ButtonIconRoot = WebConfig.GetButtonIconRoot(OSiteParam);
                PageCls OPage = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CreatePageModel(SiteId, PageId);
                string SelectStatus = 
                              "<select id=drpSelectStatus>\r\n" +
                              "     <option value=\"0\">Chưa sử dụng</option>\r\n" +
                              "     <option value=\"1\">Sử dụng</option>\r\n" +
                              "</select>\r\n";
                if (OPage.Active == 1)
                {
                    SelectStatus =
                              "<select id=drpSelectStatus>\r\n" +
                              "     <option value=\"0\">Chưa sử dụng</option>\r\n" +
                              "     <option selected value=\"1\">Sử dụng</option>\r\n" +
                              "</select>\r\n";
                }
                

                string Html =
                   " <div class=DatabaseFunction>\r\n" +
                   "    <ul>\r\n" +
                   "        <li onclick=\"javascript:ClientSavePage('" + PageId + "');\"><img class=image src=\"" + ButtonIconRoot + "/Save.png\"><div>Ghi lại</div></li>\r\n" +
                   "        <li onclick=\"javascript:ClientBack();\"><img class=image src=\"" + ButtonIconRoot + "/back.png\"><div>Quay lại</div></li>\r\n" +
                   "    </ul>\r\n" +
                   "  </div>\r\n" +
                   "  <div class=CssFormSaveUpdate>\r\n" +
                   "  <h3>Sửa thông số trang web</h3>\r\n" +
                   "  <table>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=Col1>Alias:</td>\r\n" +
                   "        <td class=Col2><input id=txtPageAlias class=textbox type=textbox value=\"" + OPage.PageAlias + "\"></td>\r\n" +
                   "    </tr>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=Col1>Tiêu đề trang:</td>\r\n" +
                   "        <td class=Col2><input id=txtPageTitle class=textbox type=textbox value=\"" + OPage.PageTitle + "\"></td>\r\n" +
                   "    </tr>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=Col1>Từ khóa:</td>\r\n" +
                   "        <td class=Col2><input id=txtPageKeyword class=textbox type=textbox value=\"" + OPage.PageKeyword + "\"></td>\r\n" +
                   "    </tr>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=Col1>Trạng thái:</td>\r\n" +
                   "        <td class=Col2>"+SelectStatus+"</td>\r\n" +
                   "    </tr>\r\n" +
                   "    <tr>\r\n" +
                   "        <td class=Col1>Thứ tự:</td>\r\n" +
                   "        <td class=Col2><input id=txtSortIndex class=textbox type=textbox value=\"" + OPage.SortIndex + "\"></td>\r\n" +
                   "    </tr>\r\n" +
                   "  </table>\r\n" +
                   "</div>\r\n";

                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }

            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideAdd(
            string SiteId, 
            string PageAlias, 
            string PageTitle,
            string PageKeyword,
            string Active,
            string SortIndex)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(PageAlias)) throw new Exception("Chưa nhập mã trang web!");
                if (string.IsNullOrEmpty(PageTitle)) throw new Exception("Chưa nhập tiêu đề trang web!");
                string AssetCode = WebSessionUtility.GetCurrentLoginUser().AssetCode;
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string DataLanguage = WebConfig.GetDataLanguage(OSiteParam);
                PageCls OPage = new PageCls();
                OPage.PageAlias = PageAlias;
                OPage.PageTitle = PageTitle;
                OPage.PageKeyword = PageKeyword;
                OPage.Active = int.Parse(Active);
                OPage.SortIndex = int.Parse(SortIndex);
                SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).AddPage(SiteId, OPage);
                OAjaxOut.HtmlContent = ServerSideReading(SiteId).HtmlContent;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }

            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideSave(
            string SiteId, 
            string PageId,
            string PageAlias, 
            string PageTitle,
            string PageKeyword,
            string Active,
            string SortIndex)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(PageAlias)) throw new Exception("Chưa nhập mã trang web!");
                if (string.IsNullOrEmpty(PageTitle)) throw new Exception("Chưa nhập tiêu đề trang web!");

                PageCls OPage = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CreatePageModel(SiteId, PageId);
                OPage.PageKeyword = PageKeyword;
                OPage.PageAlias = PageAlias;
                OPage.PageTitle = PageTitle;
                OPage.Active = int.Parse(Active);
                OPage.SortIndex = int.Parse(SortIndex);
                SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).SavePage(SiteId, PageId, OPage);
                OAjaxOut.HtmlContent = ServerSideReading(SiteId).HtmlContent;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }

            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideDelete(string SiteId, string PageId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).DeletePage(SiteId, PageId);
                OAjaxOut.HtmlContent = ServerSideReading(SiteId).HtmlContent;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }

            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideGetZoneUrl(string SiteId, string PageId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                OAjaxOut.RetUrl = "PageManZone.aspx?PageId="+PageId;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }

            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideGetPageConfigUrl(string SiteId, string PageId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                OAjaxOut.RetUrl = "PageConfig.aspx?PageId=" + PageId;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }

            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideDuplicate(string SiteId, string PageId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).DuplicatePage(SiteId, PageId);
                OAjaxOut.HtmlContent = ServerSideReading(SiteId).HtmlContent;
            }
            catch (Exception ex)
            {
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }

            return OAjaxOut;
        }


    }
}
